package com.example.springdemo.Controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.Response;

import com.example.springdemo.entity.Order;
import com.example.springdemo.entity.Orderdetail;
import com.example.springdemo.service.IOrderdetailService;
import com.example.springdemo.utils.PassToken;
import com.example.springdemo.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.converter.feed.RssChannelHttpMessageConverter;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * orderdetailController
 * 
 * @author ruoyi
 * @date 2025-05-07
 */
@RestController
@RequestMapping("/system/orderdetail")
public class OrderdetailController
{
    @Autowired
    private IOrderdetailService orderdetailService;

    /**
     * 查询orderdetail列表
     */
  @PassToken
    @GetMapping("/list")
    public ResponseResult list(Orderdetail orderdetail)
    {
//        startPage();
//        List<Orderdetail> list = orderdetailService.selectOrderdetailList(orderdetail);
//        return getDataTable(list);
        return ResponseResult.createBySuccess(200,orderdetailService.selectOrderdetailList(orderdetail),"查询成功");
    }
    @PassToken
    @GetMapping("/frontlist")
    public ResponseResult list1(Orderdetail orderdetail) {
        System.out.println(orderdetail.getDetailid());
        return ResponseResult.createBySuccess(200,orderdetail,"获取成功");
    }
    /**
     * 导出orderdetail列表
     */
//    @PreAuthorize("@ss.hasPermi('system:orderdetail:export')")
//    @Log(title = "orderdetail", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Orderdetail orderdetail)
//    {
//        List<Orderdetail> list = orderdetailService.selectOrderdetailList(orderdetail);
//        ExcelUtil<Orderdetail> util = new ExcelUtil<Orderdetail>(Orderdetail.class);
//        util.exportExcel(response, list, "orderdetail数据");
//    }

    /**
     * 获取orderdetail详细信息
     */
   @PassToken
    @GetMapping(value = "/{detailid}")
    public ResponseResult getInfo(@PathVariable("detailid") Long detailid)
    {
        Orderdetail orderdetail = orderdetailService.selectOrderdetailByDetailid(detailid);
        return ResponseResult.createBySuccess(200,detailid,"查询成功");
    }

    /**
     * 新增orderdetail
     */
   @PassToken
    @PostMapping
    public ResponseResult add(@RequestBody Orderdetail orderdetail)
    {
        int i = orderdetailService.insertOrderdetail(orderdetail);
        if (i > 0) {
            return ResponseResult.createBySuccess(200, "", "添加成功");
        } else {
            return ResponseResult.createByFail(200, "添加失败");
        }
    }

    /**
     * 修改orderdetail
     */
   @PassToken
    @PutMapping
    public ResponseResult edit(@RequestBody Orderdetail orderdetail)
    {
        int i = orderdetailService.updateOrderdetail(orderdetail);
        if (i > 0) {
            return ResponseResult.createBySuccess(200, "", "修改成功");
        } else {
            return ResponseResult.createByFail(200, "修改失败");
        }
    }

    /**
     * 删除orderdetail
     */
   @PassToken
	@DeleteMapping("/{detailids}")
    public ResponseResult remove(@PathVariable Long[] detailids)
    {
        int i = orderdetailService.deleteOrderdetailByDetailids(detailids);
        if (i > 0) {
            return ResponseResult.createBySuccess(200, "", "删除成功");
        } else {
            return ResponseResult.createByFail(200, "删除失败");
        }
    }
}
